<template>
  <div>
    <div class="g-bg m">
      <div class="g-wrap">
        <SearchInput></SearchInput>
        <SearchHead></SearchHead>
        <SearchBody :songs="songs" :flag="flag"></SearchBody>
      </div>
    </div>
    <Copyright></Copyright>
  </div>
</template>

<script>
import SearchInput from "@/pages/searchPage/SearchInput.vue";
import SearchHead from "@/pages/searchPage/SearchHead.vue";
import SearchBody from "@/pages/searchPage/SearchBody.vue";
import { getCloudsearch } from "@/api/index.js";
import { shallowRef } from "@vue/reactivity";
import { useRoute } from "vue-router";
import { watch } from "@vue/runtime-core";
import Copyright from "@/encapsulation/Copyright.vue";
import { ref } from "vue";

export default {
  name: "SearchPage",
  components: { SearchInput, SearchHead, SearchBody, Copyright },
  setup() {
    let songs = shallowRef(null);
    const route = useRoute();

    let flag = ref(true);

    watch(
      route,
      (value) => {
        flag.value = false;
        getCloudsearch(value.query.s, 20, 1).then((response) => {
          flag.value = true;
          songs.value = response.data.result?.songs;
        });
      },
      {
        immediate: true,
      }
    );
    return {
      songs,
      flag,
    };
  },
};
</script>

<style scoped lang="less">
.m {
  margin-top: 5px;
}
</style>
